package com.bang.sharding.controller;

import com.bang.sharding.entity.FixRecords;
import com.bang.sharding.service.FixRecordsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.UUID;

/**
 * 公有关键词修复记录表(FixRecords)表控制层
 *
 * @author makejava
 * @since 2020-04-08 18:09:00
 */
@RestController
@RequestMapping("fixRecords")
public class FixRecordsController {
    /**
     * 服务对象
     */
    @Resource
    private FixRecordsService fixRecordsService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public FixRecords selectOne(Long id) {
        return this.fixRecordsService.queryById(id);
    }

    @GetMapping("insert")
    public FixRecords insert(Long id) {
        FixRecords fixRecords = new FixRecords();
        fixRecords.setId(id);
        fixRecords.setUuid(UUID.randomUUID().toString().replaceAll("-", ""));
        fixRecords.setTemplateId(id);
        fixRecords.setCreateTime(new Date());
        fixRecords.setFlag(1);
        return this.fixRecordsService.insert(fixRecords);
    }

    @GetMapping("update")
    public FixRecords update(Long id) {
        FixRecords fixRecords = new FixRecords();
        fixRecords.setId(id);
        fixRecords.setUuid(UUID.randomUUID().toString().replaceAll("-", ""));
        fixRecords.setTemplateId(id);
        fixRecords.setCreateTime(new Date());
        fixRecords.setFlag(1);
        return this.fixRecordsService.insertAndUpdate(fixRecords);
    }

}